<!DOCTYPE HTML>
<html>

<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>Elasticsearch.Nest 教程系列 7-2 搜索：Writing bool queries | 编写布尔查询 | DeepThought</title>
  <meta name="google-site-verification" content="Ei6mmDdf-cJwox1RvJOeX8Dc720fqWjZQu-Ww2BjBt4">
  
  <meta name="author" content="积慕">
  
  <meta name="description" content="Nest 7 教程,Nest7.x 教程,Elasticsearch.Nest,Elasticsearch.Nest 入门, NEST 入门,NEST上手, Nest 官方文档, NEST 翻译,Elasticsearch.Nest 中文,Elasticsearch.Nest 中文文档, Nest 中文文档,NET ElasticSearch,NET es,NEST 教程, Elasticsearch 客户端,Elasticsearch 7,Elasticsearch 7.x,NEST 7,NEST 7.x,analyzers,SearchRequest,结构化查询,级联查询,HitsMetadata,布尔查询,bool query">
  
  
  <meta name="keywords" content="Nest 7 教程,Nest7.x 教程,Elasticsearch.Nest,Elasticsearch.Nest 入门, NEST 入门,NEST上手, Nest 官方文档, NEST 翻译,Elasticsearch.Nest 中文,Elasticsearch.Nest 中文文档, Nest 中文文档,NET ElasticSearch,NET es,NEST 教程, Elasticsearch 客户端,Elasticsearch 7,Elasticsearch 7.x,NEST 7,NEST 7.x,analyzers,SearchRequest,结构化查询,级联查询,HitsMetadata,布尔查询,bool query">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
  <meta property="og:title" content="Elasticsearch.Nest 教程系列 7-2 搜索：Writing bool queries | 编写布尔查询">
  <meta property="og:site_name" content="DeepThought">

  
  <meta property="og:image" content>
  

  <link href="https://pic.zhuliang.ltd/favicon.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="alternate" href="/atom.xml" title="DeepThought" type="application/atom+xml">
  <link rel="stylesheet" href="/css/style.css" media="screen" type="text/css">

  <link rel="stylesheet" href="//at.alicdn.com/t/font_1187293_8fec2ou5fyx.css">

  <!-- <link rel="stylesheet" href="//cdn.bootcss.com/highlight.js/9.6.0/styles/github.min.css"> -->
  <!-- <script src="//cdn.bootcss.com/highlight.js/9.6.0/highlight.min.js"></script> -->
  <script src="/js/highlight.min.js"></script>

  <link rel="stylesheet" href="/css/markdown.css">

  <script src="/js/av-min.3.0.4.js"></script>
  <script src="/js/Valine.min.1.3.6.js"></script>

</head></html>

<body>
  <header id="header" class="inner"><div class="alignleft">
  <h1><a href="/">DeepThought</a></h1>
  <h2><a href="/">知识需沉淀，更需分享</a></h2>
</div>
<nav id="main-nav" class="alignright">
  <ul>
    
      <li><a href="/">首页</a></li>
    
      <li><a href="/about">关于我</a></li>
    
      <li><a href="/atom.xml">订阅RSS</a></li>
    
  </ul>
  <div class="clearfix"></div>
</nav>
<div class="clearfix"></div>
        </header>
  <div id="content" class="inner">
    <div id="main-col" class="alignleft"><div id="wrapper"><article class="post">
  
  <div class="post-content">
    <header>
      
        <div class="icon"></div>
      

 
      
  
    <h1 class="title">Elasticsearch.Nest 教程系列 7-2 搜索：Writing bool queries | 编写布尔查询</h1>
  


      
        <time datetime="2020-01-21T07:59:01.000Z">
          create: 2020-01-21 15:59:01 | update: 2020-01-23 12:15:44
            <span style="float: right;">
    <span class="post-count" id="busuanzi_container_page_pv" style="display: inline;">
        
        本文总阅读量: <span id="busuanzi_value_page_pv"></span>&nbsp;次
        <span class="blueSeparate">&nbsp;|&nbsp;</span>
        
        <span class="post-count">文章总字数:&nbsp;1.9k&nbsp;字</span>
    <span class="blueSeparate">&nbsp;|&nbsp;</span>
    <span class="post-count">阅读约需:&nbsp;8&nbsp;分钟</span>
    <br>
</span>
</span>
        </time>
      
            
    </header>
    <div class="entry">
      
      <blockquote>
<ul>
<li>本系列博文是“伪”官方文档翻译（更加本土化），并非完全将官方文档进行翻译，而是在查阅、测试原始文档并转换为自己真知灼见后的“准”翻译。有不同见解 / 说明不周的地方，还请海涵、不吝拍砖 ：）</li>
<li>官方文档见此：<a href="https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/introduction.html" target="_blank" rel="noopener">https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/introduction.html</a></li>
<li>本系列对应的版本环境：<a href="mailto:ElasticSearch@7.3.1" target="_blank" rel="noopener">ElasticSearch@7.3.1</a>，<a href="mailto:NEST@7.3.1" target="_blank" rel="noopener">NEST@7.3.1</a>，IDE 和开发平台默认为 VS2019，.NET CORE 2.1</li>
</ul>
</blockquote>
<hr>
<p>在使用查询 DSL 的时候，编写布尔查询命令会很冗长，如使用带有 2 个 should 子句的单个布尔查询：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var searchResults = this.Client.Search&lt;Project&gt;(s =&gt; s
    .Query(q =&gt; q 
        .Bool(b =&gt; b
            .Should(
                bs =&gt; bs.Term(p =&gt; p.Name, &quot;x&quot;),
                bs =&gt; bs.Term(p =&gt; p.Name, &quot;y&quot;)
            )
        )
    )
);
</code></pre>
<p>可以相像，如果有多个嵌套布尔查询，最终代码久会长成这样：</p>
<p><img src="https://pic.zhuliang.ltd/20200121165100.png-c" alt></p>
<p>为了解决代码冗长的问题，Nest 重写了一元操作符（“!”和“+”）以及二元操作符（“||”和“&amp;&amp;”）</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>对应的操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>&amp;&amp;</td>
<td>must</td>
</tr>
<tr>
<td>\</td>
<td>\</td>
<td></td>
<td>should</td>
</tr>
<tr>
<td>+</td>
<td>filter</td>
</tr>
<tr>
<td>!</td>
<td>must_not</td>
</tr>
</tbody>
</table>
<a id="more"></a>
<h1 id="重写二元操作符：”-”"><a href="#重写二元操作符：”-”" class="headerlink" title="重写二元操作符：”||”"></a>重写二元操作符：”||”</h1><p>使用重写的二元运算符“||”，可以让你更加简洁的在 should 子句中使用布尔查询。</p>
<p>基于最上面的例子，改写如下：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var firstSearchResponse = client.Search&lt;Project&gt;(s =&gt; s
    .Query(q =&gt; q.Term(p =&gt; p.Name, &quot;x&quot;) || q.Term(p =&gt; p.Name, &quot;y&quot;)
    )
);
</code></pre>
<p>同样，如果使用的是对象初始化语法的，同样可以使用“||”：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var secondSearchResponse = client.Search&lt;Project&gt;(new SearchRequest&lt;Project&gt;
{
    Query = new TermQuery { Field = Field&lt;Project&gt;(p =&gt; p.Name), Value = &quot;x&quot; } 
                || new TermQuery { Field = Field&lt;Project&gt;(p =&gt; p.Name), Value = &quot;y&quot; }
});
</code></pre>
<p>以上两种方式生成的命令相同，如下：</p>
<p></p><p class="code-caption" data-lang="json" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="json">{
  &quot;query&quot;: {
    &quot;bool&quot;: {
      &quot;should&quot;: [
        {
          &quot;term&quot;: {
            &quot;name&quot;: {
              &quot;value&quot;: &quot;x&quot;
            }
          }
        },
        {
          &quot;term&quot;: {
            &quot;name&quot;: {
              &quot;value&quot;: &quot;y&quot;
            }
          }
        }
      ]
    }
  }
}
</code></pre>
<h1 id="重写二元操作符：”-amp-amp-”"><a href="#重写二元操作符：”-amp-amp-”" class="headerlink" title="重写二元操作符：”&amp;&amp;”"></a>重写二元操作符：”&amp;&amp;”</h1><p>重写的“&amp;&amp;”二元运算符可用于简化 must 子句的布尔查询：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var firstSearchResponse = client.Search&lt;Project&gt;(s =&gt; s
    .Query(q =&gt; q.Term(p =&gt; p.Name, &quot;x&quot;) &amp;&amp; q.Term(p =&gt; p.Name, &quot;y&quot;)
    )
);

//以下用法等效于上面
var secondSearchResponse = client.Search&lt;Project&gt;(new SearchRequest&lt;Project&gt;
{
    Query = new TermQuery { Field = Field&lt;Project&gt;(p =&gt; p.Name), Value = &quot;x&quot; } 
            &amp;&amp; new TermQuery { Field = Field&lt;Project&gt;(p =&gt; p.Name), Value = &quot;y&quot; }
});
</code></pre>
<p>生成的命令均为：</p>
<p></p><p class="code-caption" data-lang="json" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="json">{
  &quot;query&quot;: {
    &quot;bool&quot;: {
      &quot;must&quot;: [
        {
          &quot;term&quot;: {
            &quot;name&quot;: {
              &quot;value&quot;: &quot;x&quot;
            }
          }
        },
        {
          &quot;term&quot;: {
            &quot;name&quot;: {
              &quot;value&quot;: &quot;y&quot;
            }
          }
        }
      ]
    }
  }
}
</code></pre>
<p>NEST 客户端会对像上面这样的请求合并为一次 bool 查询。</p>
<h1 id="重写一元操作符：”-”"><a href="#重写一元操作符：”-”" class="headerlink" title="重写一元操作符：”!”"></a>重写一元操作符：”!”</h1><p>重写的一元操作附“!”主要面向含有 must_not 子句的查询。</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var firstSearchResponse = client.Search&lt;Project&gt;(s =&gt; s
    .Query(q =&gt; !q
        .Term(p =&gt; p.Name, &quot;x&quot;)
    )
);

//等效于
var secondSearchResponse = client.Search&lt;Project&gt;(new SearchRequest&lt;Project&gt;
{
    Query = !new TermQuery { Field = Field&lt;Project&gt;(p =&gt; p.Name), Value = &quot;x&quot; }
});
</code></pre>
<p>以上两种方式最终生成的命令如下：</p>
<p></p><p class="code-caption" data-lang="json" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="json">{
  &quot;query&quot;: {
    &quot;bool&quot;: {
      &quot;must_not&quot;: [
        {
          &quot;term&quot;: {
            &quot;name&quot;: {
              &quot;value&quot;: &quot;x&quot;
            }
          }
        }
      ]
    }
  }
}
</code></pre>
<p>两个含有“!”运算符的查询可以用“&amp;&amp;”进行合并，以形成带有 2 个 must_not 子句的单个布尔查询。</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">//伪代码：
!q.Query() &amp;&amp; !q.Query()
或者
!Query &amp;&amp; !Query
</code></pre>
<h1 id="重写一元操作符：”-”-1"><a href="#重写一元操作符：”-”-1" class="headerlink" title="重写一元操作符：”+”"></a>重写一元操作符：”+”</h1><p>通过使用一元“+”运算符可以将查询转换为<strong>带有过滤子句的布尔查询</strong>。</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var firstSearchResponse = client.Search&lt;Project&gt;(s =&gt; s
    .Query(q =&gt; +q  //+运算符
        .Term(p =&gt; p.Name, &quot;x&quot;)
    )
);
//或者以下方式
var secondSearchResponse = client.Search&lt;Project&gt;(new SearchRequest&lt;Project&gt;
{
    Query = +new TermQuery { Field = Field&lt;Project&gt;(p =&gt; p.Name), Value = &quot;x&quot; }
});
</code></pre>
<p>最终生成的命令如下：</p>
<p></p><p class="code-caption" data-lang="json" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="json">{
  &quot;query&quot;: {
    &quot;bool&quot;: {
      &quot;filter&quot;: [
        {
          &quot;term&quot;: {
            &quot;name&quot;: {
              &quot;value&quot;: &quot;x&quot;
            }
          }
        }
      ]
    }
  }}
</code></pre>
<p>以上命令将再过滤器上下文中运行，当你不需要使用 _score 来排序的时候，使用这种方式可以提高性能。</p>
<p>跟一元运算符“!”类似，使用“+”的 2 个子句同样可以使用“&amp;&amp;”进行合并，形成带有 2 个 filter 子句的单个布尔查询。</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">//伪代码：
+q.Query() &amp;&amp; +q.Query()
或者
 +Query &amp;&amp; +Query
</code></pre>
<h1 id="使用“-amp-amp-”合并查询"><a href="#使用“-amp-amp-”合并查询" class="headerlink" title="使用“&amp;&amp;”合并查询"></a>使用“&amp;&amp;”合并查询</h1><p>1.当将多个 Term 级别的查询用二元运算符“&amp;&amp;”（其中某些或所有查询都应用了一元运算符）进行连接，如：</p>
<p></p><p class="code-caption" data-lang="sh" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="sh">term &amp;&amp; term &amp;&amp; term
</code></pre>
<p>NEST 会形成如下的嵌套顺序：</p>
<p><img src="https://pic.zhuliang.ltd/20200218170713.png" alt></p>
<ul>
<li>Nest 会自动将 &amp;&amp; 连接的条件限制在单个 bool 查询中。</li>
</ul>
<h1 id="使用“-”合并查询或-should-子句"><a href="#使用“-”合并查询或-should-子句" class="headerlink" title="使用“||”合并查询或 should 子句"></a>使用“||”合并查询或 should 子句</h1><p>在上面的示例（描述“||”的小节）中，NEST将合并多个“||”或 should 子句到单个布尔查询中 。</p>
<p>像下面这样的组合：</p>
<p></p><p class="code-caption" data-lang="sh" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="sh">term || term || term
</code></pre>
<p>最终会被解析为：<br><img src="https://pic.zhuliang.ltd/20200121173656.png" alt></p>
<p>不过，布尔查询并非完全遵循编程语言中的布尔逻辑，如：</p>
<p></p><p class="code-caption" data-lang="sh" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="sh">term1 &amp;&amp; (term2 || term3 || term4)
</code></pre>
<p>需要特别<strong>注意</strong>，以上组合<strong>并不会</strong>被解析为以下关系：</p>
<p><img src="https://pic.zhuliang.ltd/20200220152411.png" alt></p>
<p><strong>原因：</strong></p>
<ul>
<li>当布尔查询中仅包含 should 子句时，表示的是必须要有一个被匹配上。</li>
<li>但当该布尔查询还具有 must 子句时，<strong>should 子句则会充当提升因子，这意味着它们不必匹配</strong>，但是如果匹配了，则该文档的相关性得分将得到提升。也就是说，should 子句的行为语义会根据 must 子句的存在而发生改变。</li>
</ul>
<p>因此，对于“term1 &amp;&amp; (term2 || term3 || term4)”这样的组合，你将得到<strong>仅</strong>包含 term1 的结果，<strong>这跟使用重载运算符时的预期是不相符</strong>。</p>
<p>在构建搜索查询时，将 should 子句用作提升因子非常有用，你可以将实际的 bool 查询与NEST的运算符重载混合后进行匹配。</p>
<p>另外需要注意下，当 2 个布尔查询仅包含 should 子句的时候，NEST 不会进行合并，如下：</p>
<p></p><p class="code-caption" data-lang="sh" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="sh">bool(should=term1, term2, term3, term4, minimum_should_match=2) || term5 || term6
</code></pre>
<ul>
<li>如果 NEST 发现运算符“||”左右两边<strong>仅包含</strong> should 子句，那么此时 NEST 会改变第一个布尔查询中的 minimum_should_match 参数的原意。<ul>
<li>像上面的的示例 <strong>仅会在 term5 和 term6 上进行匹配</strong> 。</li>
</ul>
</li>
</ul>
<h1 id="不会合并处理的情况"><a href="#不会合并处理的情况" class="headerlink" title="不会合并处理的情况"></a>不会合并处理的情况</h1><p>如果设置了任何查询元数据，如设置了 boost 或 name 等元数据，则 NEST 不会合并布尔查询，而是会将其视为已锁定，如下：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">Assert(
    q =&gt; q.Bool(b =&gt; b.Name(&quot;leftBool&quot;).Should(mq =&gt; mq.Query()))
         || q.Bool(b =&gt; b.Name(&quot;rightBool&quot;).Should(mq =&gt; mq.Query())),
    new BoolQuery { Name = &quot;leftBool&quot;, Should = new QueryContainer[] { Query } }
    || new BoolQuery { Name = &quot;rightBool&quot;, Should = new QueryContainer[] { Query } },
    c =&gt; AssertDoesNotJoinOntoLockedBool(c, &quot;leftBool&quot;));
  //或者下面这种
Assert(
    q =&gt; q.Bool(b =&gt; b.Should(mq =&gt; mq.Query()))
         || q.Bool(b =&gt; b.Name(&quot;rightBool&quot;).Should(mq =&gt; mq.Query())),
    new BoolQuery { Should = new QueryContainer[] { Query } }
    || new BoolQuery { Name = &quot;rightBool&quot;, Should = new QueryContainer[] { Query } },
    c =&gt; AssertDoesNotJoinOntoLockedBool(c, &quot;rightBool&quot;));

 //或者下面这种
 Assert(
    q =&gt; q.Bool(b =&gt; b.Name(&quot;leftBool&quot;).Should(mq =&gt; mq.Query()))
         || q.Bool(b =&gt; b.Should(mq =&gt; mq.Query())),
    new BoolQuery { Name = &quot;leftBool&quot;, Should = new QueryContainer[] { Query } }
    || new BoolQuery { Should = new QueryContainer[] { Query } },
    c =&gt; AssertDoesNotJoinOntoLockedBool(c, &quot;leftBool&quot;));
</code></pre>
<h1 id="性能优化建议"><a href="#性能优化建议" class="headerlink" title="性能优化建议"></a>性能优化建议</h1><p>假设你有很多 must 子句，使用“&amp;=”进行合并</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var c = new QueryContainer();
var q = new TermQuery { Field = &quot;x&quot;, Value = &quot;x&quot; };

for (var i = 0; i &lt; 1000; i++)
{
    c &amp;= q;
}
</code></pre>
<p>性能分析结果如下：<br><img src="https://pic.zhuliang.ltd/20200121180936.png-c" alt></p>
<ul>
<li>分配了过多的对象，这会导致 GC 压力。</li>
</ul>
<p>因为已经知道了布尔查询的大致形态，因此可以通过如下方式来进行优化：</p>
<ul>
<li>因为知道最终是一个布尔查询，所以这里可以直接用布尔查询来代替 Term 查询合并。<br><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><pre><code class="csharp">QueryContainer q = new TermQuery { Field = &quot;x&quot;, Value = &quot;x&quot; };
var x = Enumerable.Range(0, 1000).Select(f =&gt; q).ToArray();
var boolQuery = new BoolQuery
{
  Must = x
};
</code></pre>
</li>
</ul>
<p>性能分析结果如下：</p>
<p><img src="https://pic.zhuliang.ltd/20200121181134.png-c" alt></p>

      

      <div>
        
        <div style="background-color: rgb(255, 23, 0);user-select: auto;height: 3px;width:100%;margin-top: 40px;margin-bottom:15px;"></div>

<!-- <p>常言道：学然后知不足，教然后知困。</p>
<p>我知道你的焦虑，一起共进加油：P</p>
<p>关不关注都无所谓，会根据生活节奏紧凑度定期分享些开发经验、搬砖生涯、痛点、感悟。</p>
<p>
        <img src="https://pic.zhuliang.ltd/20191213133908.gif" alt="欢迎关注我的订阅号：P" />
</p> -->
<ul class="post-copyright" style="margin-left:0px;">
    <li class="post-copyright-author">
        <strong>本文作者：</strong>积慕
    </li>
    <li class="post-copyright-link">
        <strong>本文链接：</strong>
        <a href="/2020/01/backend/Elasticsearch-Nest-Writing-Queries.html" title="Elasticsearch.Nest 教程系列 7-2 搜索：Writing bool queries | 编写布尔查询">https://blog.zhuliang.ltd/2020/01/backend/Elasticsearch-Nest-Writing-Queries.html</a>
    </li>
    <li class="post-copyright-license">
        <strong>版权： </strong>
        本站文章均采用 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" rel="external nofollow"
            target="_blank">CC BY-NC-SA 3.0 CN</a> 许可协议，请勿用于商业，转载注明出处！
    </li>
</ul>
        
      </div>
    </div>

    <footer>
      
      
  
  <div class="categories">
    <a href="/categories/backend/">backend</a>
  </div>

      
  
  <div class="tags">
    <a href="/tags/教程/">教程</a>, <a href="/tags/Elasticsearch-Nest系列/">Elasticsearch.Nest系列</a>, <a href="/tags/Elasticsearch/">Elasticsearch</a>
  </div>

      <!-- 
  <div class="addthis addthis_toolbox addthis_default_style">
    
    
      <a class="addthis_button_tweet"></a>
    
    
      <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
    
    
      <a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
    
    <a class="addthis_counter addthis_pill_style"></a>
  </div>
  <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js"></script>
 -->
      
      <div class="clearfix"></div>
    </footer>
  </div>
</article>

<!-- 
<section id="comment">
  <h1 class="title">留言</h1>

  <div id="vcomments" style="background-color: #fff"></div>
  <script>
    new Valine({
      el: '#vcomments',
      appId: 'aTPKmG6tjDo3CbIXzAPzrj4X-gzGzoHsz',
      appKey: 'hNgWFneNpEcMnBJclPQnDgsd',
      notify: true,
      verify: true, //验证码
      avatar: 'monsterid', //https://valine.js.org/avatar.html
      placeholder: '请输入你的评论'
    })
  </script>
</section>
 --> <!--启用/关闭 LeanCloud 评论--></div></div>
    <aside id="sidebar" class="alignright">
  
<div class="widget tag">
  <h3 class="title"><i class="iconfont icon-category"></i>&nbsp;&nbsp;分类</h3>
  <ul class="entry">
  
    <li><a href="/categories/Obsidian/">Obsidian</a><small>1</small></li>
  
    <li><a href="/categories/PowerUser/">PowerUser</a><small>4</small></li>
  
    <li><a href="/categories/backend/">backend</a><small>57</small></li>
  
    <li><a href="/categories/frontend/">frontend</a><small>9</small></li>
  
    <li><a href="/categories/operations/">operations</a><small>5</small></li>
  
    <li><a href="/categories/提前退休/">提前退休</a><small>2</small></li>
  
  </ul>
</div>


  
<div class="widget tag">
  <h3 class="title"><i class="iconfont icon-new3"></i>&nbsp;&nbsp;最新文章</h3>
  <ul class="entry">
    
      <li>
        <a href="/2024/11/PowerUser/install-docker-in-pve-lxc.html">1. 通过 PVE LXC 搭建 docker 环境</a>
      </li>
    
      <li>
        <a href="/2024/11/Obsidian/obsidian-render-pie-chart.html">2. 2 套用于 obsidian 的生成时间占用饼图脚本示例，基于 templater， charts，echarts+dataview</a>
      </li>
    
      <li>
        <a href="/2024/10/PowerUser/fix-ios18-samba-readonly-issue.html">3. 解决 ios 18（包括ipadOS 18） 下通过文件(files app)连接 samba 服务器，目录变成只读权限的问题</a>
      </li>
    
      <li>
        <a href="/2023/07/operations/how-to-use-pm2.html">4. PM2 的安装、配置和使用</a>
      </li>
    
      <li>
        <a href="/2023/07/backend/expose-intranet-netcoreapi-to-internet.html">5. 通过 DDNS+显性URL 把内网部署的.NET CORE WEBAPI 项目暴露到公网中</a>
      </li>
    
  </ul>
</div>


  
<div class="widget tag">
  <h3 class="title"><i class="iconfont icon-tag"></i>&nbsp;&nbsp;标签</h3>
  <ul class="entry">
  
    <li><a href="/tags/net-core/">.net core</a><small>12</small></li>
  
    <li><a href="/tags/Debian/">Debian</a><small>2</small></li>
  
    <li><a href="/tags/Docker/">Docker</a><small>1</small></li>
  
    <li><a href="/tags/Elasticsearch/">Elasticsearch</a><small>35</small></li>
  
    <li><a href="/tags/Elasticsearch-Nest系列/">Elasticsearch.Nest系列</a><small>35</small></li>
  
    <li><a href="/tags/Obsidian/">Obsidian</a><small>1</small></li>
  
    <li><a href="/tags/PVE/">PVE</a><small>2</small></li>
  
    <li><a href="/tags/StackExchange-Redis系列/">StackExchange.Redis系列</a><small>12</small></li>
  
    <li><a href="/tags/centos/">centos</a><small>3</small></li>
  
    <li><a href="/tags/flex/">flex</a><small>1</small></li>
  
    <li><a href="/tags/ios/">ios</a><small>1</small></li>
  
    <li><a href="/tags/javascript/">javascript</a><small>1</small></li>
  
    <li><a href="/tags/linux/">linux</a><small>4</small></li>
  
    <li><a href="/tags/nginx/">nginx</a><small>2</small></li>
  
    <li><a href="/tags/nuget/">nuget</a><small>2</small></li>
  
    <li><a href="/tags/react/">react</a><small>6</small></li>
  
    <li><a href="/tags/styled-components/">styled-components</a><small>1</small></li>
  
    <li><a href="/tags/内网穿透/">内网穿透</a><small>4</small></li>
  
    <li><a href="/tags/培训讲义/">培训讲义</a><small>2</small></li>
  
    <li><a href="/tags/基础知识/">基础知识</a><small>2</small></li>
  
    <li><a href="/tags/性能优化/">性能优化</a><small>2</small></li>
  
    <li><a href="/tags/教程/">教程</a><small>64</small></li>
  
    <li><a href="/tags/理财/">理财</a><small>2</small></li>
  
    <li><a href="/tags/生命周期/">生命周期</a><small>1</small></li>
  
    <li><a href="/tags/经验/">经验</a><small>4</small></li>
  
  </ul>
</div>


  
  <script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
  <script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
  <div class="widget tag">
    <h3 class="title"><i class="iconfont icon-cloud1"></i>&nbsp;&nbsp;标签云</h3>
    <div id="myCanvasContainer" class="widget tagcloud">
      <canvas width="250" height="250" id="resCanvas" style="width:100%">
        <a href="/tags/net-core/" style="font-size: 17.14px;">.net core</a> <a href="/tags/Debian/" style="font-size: 11.43px;">Debian</a> <a href="/tags/Docker/" style="font-size: 10px;">Docker</a> <a href="/tags/Elasticsearch/" style="font-size: 18.57px;">Elasticsearch</a> <a href="/tags/Elasticsearch-Nest系列/" style="font-size: 18.57px;">Elasticsearch.Nest系列</a> <a href="/tags/Obsidian/" style="font-size: 10px;">Obsidian</a> <a href="/tags/PVE/" style="font-size: 11.43px;">PVE</a> <a href="/tags/StackExchange-Redis系列/" style="font-size: 17.14px;">StackExchange.Redis系列</a> <a href="/tags/centos/" style="font-size: 12.86px;">centos</a> <a href="/tags/flex/" style="font-size: 10px;">flex</a> <a href="/tags/ios/" style="font-size: 10px;">ios</a> <a href="/tags/javascript/" style="font-size: 10px;">javascript</a> <a href="/tags/linux/" style="font-size: 14.29px;">linux</a> <a href="/tags/nginx/" style="font-size: 11.43px;">nginx</a> <a href="/tags/nuget/" style="font-size: 11.43px;">nuget</a> <a href="/tags/react/" style="font-size: 15.71px;">react</a> <a href="/tags/styled-components/" style="font-size: 10px;">styled-components</a> <a href="/tags/内网穿透/" style="font-size: 14.29px;">内网穿透</a> <a href="/tags/培训讲义/" style="font-size: 11.43px;">培训讲义</a> <a href="/tags/基础知识/" style="font-size: 11.43px;">基础知识</a> <a href="/tags/性能优化/" style="font-size: 11.43px;">性能优化</a> <a href="/tags/教程/" style="font-size: 20px;">教程</a> <a href="/tags/理财/" style="font-size: 11.43px;">理财</a> <a href="/tags/生命周期/" style="font-size: 10px;">生命周期</a> <a href="/tags/经验/" style="font-size: 14.29px;">经验</a>
      </canvas>
    </div>
  </div>




</aside>
    <div class="clearfix"></div>
  </div>
  <footer id="footer" class="inner"><div class="alignleft">

  
  &copy; 2018 - 2024 &nbsp;<a href='/about'>积慕</a>
  
  &nbsp;&nbsp;<a href='https://www.cnblogs.com/deepthought/'>我的博客园地址</a>
  &nbsp;&nbsp;finalclassic#outlook.com
</div>

<div class="clearfix"></div>
<div>
  本站主题基于：<a href='https://github.com/hexojs/hexo-theme-light' rel="external nofollow">hexo-theme-light</a>
</div>
<div id="busuanzi_container_site_pv">
  本站总访问量&nbsp;<span id="busuanzi_value_site_pv"></span>&nbsp;次
</div>
<div style="width:300px;margin:0 auto; padding:20px 0;">
  <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=31011702004805" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
    <img src="https://pic.zhuliang.ltd/20200102164648.png" style="float:left;"><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">沪公网安备 31011702004805号</p></a>
</div></footer>
  <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>




<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
(function($){
  $('.fancybox').fancybox();
})(jQuery);
</script>


<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>

<!-- <script src="/js/busuanzi.pure.mini.js"></script> -->
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?ea793b9c8d6b31df666a6bc15038e246";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>
</body>
</html>
